Options for pack method are | |
---|---|
side |
|
ipadx , ipady | Internal padding. Default is 0. |
padx, pady | External padding. Default is 0. |
fill |
Determines whether widget fills any extra space allocated to it by the packer, or keeps its own minimal dimensions
|
expand | When set to true, widget expands to fill any space not otherwise used in widget's parent. |
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.btn1=Button(self,text="OK") self.btn1.pack(fill=X) self.btn2=Button(self,text="Cancel") self.btn2.pack(side=BOTTOM,fill=X) self.btn3=Button(self,text="Yes") self.btn3.pack(side=LEFT,fill=Y) self.btn4=Button(self,text="No") self.btn4.pack(side=RIGHT,fill=Y) self.btn5=Button(self,text="CCIT") self.btn5.pack(fill=X) frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() lst=["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"] for nm in lst: self.btn=Button(self,text=nm,bg="white") self.btn.pack(fill=X,padx=5,pady=5,ipady=5) frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() lst=["Next","Previous","First","Last","Exit"] for nm in lst: self.btn=Button(self,text=nm,bg="white") self.btn.pack(side=LEFT,fill=X,padx=5,pady=5,ipady=5) frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.geometry("300x300") self.b1=Button(self,text="OK") self.b1.pack(side=TOP,fill=X) self.b2.pack(side=BOTTOM,fill=X) self.b3=Button(self,text="CCIT",bg="yellow") self.b3.pack(fill=BOTH,expand=True) frm=MyFrame() frm.mainloop()